import QtQuick 2.14
import QtQuick.Controls 2.14

TextField {
    id: customTextField
    
    property color borderColor: "#E0E0E0"
    property color focusedBorderColor: "#2196F3"
    property color errorBorderColor: "#F44336"
    property bool hasError: false
    property string errorText: ""
    
    implicitWidth: 200
    implicitHeight: 40
    
    leftPadding: 12
    rightPadding: 12
    topPadding: 8
    bottomPadding: 8
    
    background: Rectangle {
        radius: 4
        border.width: 2
        border.color: {
            if (hasError) return errorBorderColor
            if (customTextField.activeFocus) return focusedBorderColor
            return borderColor
        }
        color: customTextField.enabled ? "white" : "#F5F5F5"
        
        Behavior on border.color {
            ColorAnimation {
                duration: 150
            }
        }
    }
    
    color: customTextField.enabled ? "#212121" : "#757575"
    selectionColor: "#2196F3"
    selectedTextColor: "white"
    
    // 错误提示
    Text {
        id: errorLabel
        anchors.top: parent.bottom
        anchors.topMargin: 4
        anchors.left: parent.left
        text: errorText
        color: errorBorderColor
        font.pixelSize: 12
        visible: hasError && errorText !== ""
    }
}